package com.pdstudio.carrecom.ui.activity;

import com.pdstudio.carrecom.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * 类: ActivityWebView <br>
 * 描述: WebView公共类 <br>
 * 作者: ws <br>
 * 时间: 2015-6-10 下午9:44:16
 */
public class ActivityWebView extends Activity implements OnClickListener {

	private WebView mWebView;

	private TextView txtTitle;
	private ImageView ivBack;

	private String mTitle = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_webview);
		
		Intent intent = getIntent();
		String url = intent.getStringExtra("url");
		mTitle = intent.getStringExtra("title");
		
		initTitle();

		mWebView = (WebView) findViewById(R.id.webview);
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.loadUrl(url);

	}

	/**
	 * 方法: initTitle <br>
	 * 描述: 初始化页面标题 <br>
	 * 作者: ws <br>
	 * 时间: 2015-5-24 下午5:46:11
	 */
	private void initTitle() {
		txtTitle = (TextView) findViewById(R.id.title_text_nav);
		txtTitle.setText(mTitle);
		ivBack = (ImageView) findViewById(R.id.title_back);
		ivBack.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			finish();
			break;
		}

	}

	// @Override
	// public boolean onKeyDown(int keyCode, KeyEvent event) {
	//
	// if (mWebView.canGoBack() && keyCode == KeyEvent.KEYCODE_BACK) {
	// mWebView.goBack(); // goBack()表示返回webView的上一页面
	// return true;
	// }
	// return false;
	// }
}
